<?php
namespace app\company\controller;
use app\company\model\Sources as SourcesModel;
use app\company\model\NormField as NormModel;
use app\company\model\NormCategory as NormCateModel;
class Sources extends Base
{
	public function index(){
		$sources  = new SourcesModel;
		$list = $sources->order('id DESC')->paginate();
		$this->assign('list', $list);
		return $this->fetch();
	}

	public function add(){
		if (request()->isPost()) {
			$sources  = new SourcesModel;
			$result = $sources->allowField(true)
		    ->data(request()->post(), true)
		    ->save();

		    if($result){
		    	$this->success('添加成功','index');
		    }else{
		    	$this->error('添加失败');
		    }

		}else{
			return $this->fetch();
		}
		
	}

	public function edit($id){
		if (request()->isPost()) {
			
			$sources  = new SourcesModel;
			$result = $sources->isUpdate(true)->save(request()->post());
		    if($result){
		    	$this->success('修改成功','index');
		    }else{
		    	$this->error('修改失败');
		    }

		}else{
			$sources  = new SourcesModel;
			$item =$sources::get($id);
			$this->assign('item',$item);
			return $this->fetch();
		}

	}

	public function delete($id){

		$sources  = new SourcesModel;
		$result = $sources::destroy($id);
		if($result){
			$this->success('删除成功','index');
		}else{
			$this->error('删除失败');
		}

	}


	public function norm_category(){
			$normCate = new NormCateModel;
		
	}
	
	public function norm(){
			$norm = new NormModel;

			$list = $norm->where('status','1')->order('sort')->select();

			$this->assign('norm',$norm);

			$this->fetch();
	}

	public function import_excel(){


	}

	
	
}